#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#define MAXSIZE 5
typedef struct peopleMes {
	char name[10];
	char gendar[10];
	int age;
}Person;  
typedef struct {
	Person people[MAXSIZE];
	int length;
} SqList;

//初始化线性表 
void InitSqList(SqList *&L){
	L = (SqList *)malloc(sizeof(SqList));
	L->length = 0;
}

//销毁线性表
void DestorySqList(SqList *&L){
	free(L);
}

//判断表是否为空
bool ListEmpty(SqList *L){
	return (L->length == 0);
} 

//求线性表长度 
int ListLength(SqList *L){
	return L->length;
} 

//输出线性表 
void DispList(SqList *L){
	int i;
	if(ListEmpty(L)) {
		return;
	}
	for (i = 0;i < L->length; i++) {
		printf("%s\n", L->people[i]);
	}
}

//插入一个元素 
bool ListInsert(SqList *&L, int i, Person e){
	int j;
	if(i < 1 || i > L->length+1){
		return false;
	}
	i--;
	for(j = L->length; j > i; j--){
		L->people[j] = L->people[j-1]; 
	}
	L->people[i] = e;
	L->length++;
	return true;
}

//删除一个元素 
bool DeleteElem(SqList *&L, int i){
	if(i<0 || i>L->length){
		return false;
	}  
	int j;
	i--;
	for(j = i; j < L->length -1;j++){
		L->people[j]=L->people[j+1];
	}
	return true;
}

int main(void)
{
	SqList *L;
	InitSqList(L);
	L->length = 3;
	L->people[0].age = 85;
	strcpy(L->people[0].gendar, "man");
	strcpy(L->people[0].name, "P0卡卡罗特");
	strcpy(L->people[1].name, "P1悟天");
	L->people[1].age = 45;
	strcpy(L->people[2].name,"P2悟饭");
	bool isEmpty = ListEmpty(L);
	printf("isEmpty = %d\n", isEmpty);
	int length = ListLength(L);
	printf("length = %d\n", length);
	printf("--------\n");
	Person test;
	strcpy(test.name, "布玛");
	strcpy(test.gendar,"woman");
	test.age = 48;
	printf("%s\n",test.name);
	printf("%s\n",test.gendar);
	int a = ListInsert(L, 2, test);
	printf("%s\n",L->people[1]);
	printf("%s\n",L->people[2]);
	int b = DeleteElem(L, 2);
	printf("删除成功....\n");
	printf("%s\n",L->people[1]);
	printf("%s\n",L->people[2]);
	return 0;
}
